package com.mark.spring.annotation.register.condition;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.Conditional;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * @Description: Conditional引导类
 * @Author: Mark
 * @CreateDate: 2019/9/1 21:50
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 *
 * @see Conditional
 * @see Condition
 *
 * 定义：
 * <code>@Conditional<code/>按照一定的条件进行判断，满足条件的时候才往容器中注册Bean
 *
 */
@ComponentScan(basePackages = {"com.mark.spring.annotation.register.condition"})
public class ConditionalBootstrap {

    public static void main(String[] args) {
        //加载配置，获取bean
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConditionalBootstrap.class);

        //获取天气的bean
        Map<String, Weather> weatherMap = applicationContext.getBeansOfType(Weather.class);
        Assert.notNull(weatherMap,"获取到bean为空！");

        //关闭上下文
        applicationContext.close();
    }
}
